%% -------------------------------------------------------------------------------------------------
%% Generate Period Wavform Data
%% -------------------------------------------------------------------------------------------------
function [DataSize PeriodWavData] = fun_GenPeriodWavform(PeriodCNT, Delay, Signal, Repeat_N)

    
    %% Check
    SignalLength    = length(Signal);
    SignalZeroNum   = PeriodCNT - Delay - SignalLength;
    
    if (SignalZeroNum < 0)
        disp('Input Signal is not correct');
    
    elseif (SignalZeroNum == 0)
        if (Delay > 0) 
            Signal_Cell(1 : Delay) = 0;
            Signal_Cell(1 + Delay : Delay + SignalLength) = Signal;
        else 
            Signal_Cell(1 : SignalLength) = Signal;   
        end 
    else 
        if (Delay > 0) 
            Signal_Cell(1 : Delay) = 0;
            Signal_Cell(1 + Delay : Delay + SignalLength) = Signal;
        else 
            Signal_Cell(1 : SignalLength) = Signal;   
        end
        
        Signal_Cell(Delay + SignalLength + 1 : PeriodCNT) = 0;
                                                     
    end 
    
    
    if (Repeat_N >= 1) 
        
        for (i = 1 : Repeat_N)
        
            PeriodWavData((i - 1) * PeriodCNT + 1 : i * PeriodCNT) = Signal_Cell;
        end
    end

    DataSize = length(PeriodWavData);
    
end
